class ClassName { static { Statements ---------- } --- }
class Student { private int rollno; private String name; private static int count=1000; public void showData() { System.out.print("RollNo is "+rollno); System.out.println("Name is "+name); } public Student( String n ) { name=n; rollno=count; count=count+1; } } class demo { public static void main(String args[]) { Student a=new Student("Amit Jain"); Student b=new Student("Seeta Rathi"); Student c=new Student("Raja Rao"); a.showData(); b.showData(); c.showData(); } }
RollNo is 1000 Name is Amit Jain RollNo is 1001 Name is Seeta Rathi RollNo is 1002 Name is Raja Rao
class Test { Static { System.out.println("SIB"); } public Test( ) { System.out.println("Constructor"); } } class demo { public static void main(String args[]) { Test a=new Test(); Test b=new Test(); } }
SIB Constructor Constructor